/*
 * MatingSystem.cpp
 *
 *  Created on: 11-01-2011
 *      Author: Przemek
 */

#include "world/creation/MatingSystem.hpp"
#include "world/creation/GenotypeMutator.hpp"
#include "world/Individual.hpp"
#include "utils/Randomizer.hpp"
using std::vector;

MatingSystem::MatingSystem(Individual& first, Individual& second) :
	first(first), second(second)
{

}

void MatingSystem::mate(vector<Individual*>& children)
{
	first.getState().clearLibidoValue();
	second.getState().clearLibidoValue();

	const int childrenCount = Randomizer::nextInt(1, 3);
	for(int i = 0; i < childrenCount; ++i)
	{
		children.push_back(produceChild());
	}
}

Individual* MatingSystem::produceChild()
{
	GenotypeMutator genotypeMutator(first.getGenotype(), second.getGenotype());
	Individual* child = new Individual(genotypeMutator.mutate());
	child->setPosition(first.getPosition());
	return child;
}

Vector MatingSystem::generateChildPosition() const
{
	static const float DISTANCE = 50.0f;

	return first.getBounds().getCenter() + MathUtils::getUnitCircleCoordinatesForAngle(
			Randomizer::nextAngleInDegrees()) * DISTANCE;
}
